#!/usr/bin/env python
# _*_ coding: UTF-8 _*_
#Echo Client

import socket, traceback, sys

host = ''
port = 51423

#现在很多机器需要调节大了才有效果，buf比较大
# data = "x" * 10485760
data = "x" * 1048576000

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))

byteswritten = 0
while byteswritten < len(data):
    startpos = byteswritten
    endpos = min(byteswritten + 1024, len(data))
    byteswritten += s.send(data[startpos:endpos])
    sys.stdout.write("Wrote %d bytes\r" % byteswritten)
    sys.stdout.flush()


s.shutdown(1)


print "All data sent."

while True:
    buf = s.recv(1024)
    if not len(buf):
        break

    sys.stdout.write(buf)



